# Path variables
CUDA_INSTALL_PATH ?= /usr/local/cuda

# Compiler and Linker
CXX := g++
CC := gcc
LINK := g++ -fPIC
NVCC  := nvcc

# Includes
INCLUDES = -I. -I$(CUDA_INSTALL_PATH)/include -I$(CUDA_INSTALL_PATH)/samples/common/inc

# Common flags
COMMONFLAGS += $(INCLUDES) -DLINUX
NVCCFLAGS += -m64 $(COMMONFLAGS) 
CXXFLAGS += -m64 $(COMMONFLAGS)
CFLAGS += -O3 $(COMMONFLAGS)

LIB_CUDA := -L$(CUDA_INSTALL_PATH)/lib64 -lcudart -lcuda

OBJS = permUtility.o perm_kernel_mt32.o gpuMain.o
TARGET = PERMUTE
LINKLINE = $(LINK) -o $(TARGET) $(LIB_CUDA) $(OBJS)

ALL =	permUtility.o perm_kernel_mt32.o gpuMain.o $(TARGET)

all: $(ALL)

clean:
	rm -rf *.o
	rm $(TARGET)
	
.SUFFIXES: .c .cpp .cu .o
	
%.c.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

%.o: %.cu
	$(NVCC) $(NVCCFLAGS) -c $<

%.cpp.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

permUtility.o: permUtility.cpp
perm_kernel_MT32.o: perm_kernel_mt32.cu
gpuMain.o: gpuMain.cpp

$(TARGET): $(OBJS)
	$(LINKLINE)
